package com.jiepu.homework.module5.exercise5;

import java.util.Arrays;

public class Bank { // 银行
	
	private Customer[] customers; // 银行的客户
	
	private int custNum; // 客户的数量
	
	public Bank() {
		customers = new Customer[100];
		custNum = 0;
	}
	
	public void addCustomer(Customer customer) { // 添加客户
		ensureCapacity();
		customers[custNum++] = customer;
	}
	
	// 自动扩容方法
	public void ensureCapacity() {
		if (custNum >= customers.length) {
			int oldCapacity = customers.length;
			int newCapacity = oldCapacity + (oldCapacity >> 1);
			customers = Arrays.copyOf(customers, newCapacity);
		}
	}
	
	public Customer getCustomer(int index) { // 获取指定位置的客户
		return customers[index];
	}
	
	public int getCustomerNum() {
		return this.custNum;
	}
	

}
